﻿using System.Windows;
using GSMS.Common;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;

namespace LicenceManager.ViewModel
{
    public class LicenseManagerViewModel : ViewModelBase
    {
        private LicenseManagerViewModel()
        {
            this.CommandCopy = new RelayCommand(CommandCopyExecute);
            this.CommandGenerate = new RelayCommand(CommandGenerateExecute);
        }

        private static LicenseManagerViewModel instance;
        public static LicenseManagerViewModel Instance
        {
            get { return instance ?? (instance = new LicenseManagerViewModel()); }
        }

        private string hashString;
        public string HashString
        {
            get { return hashString; }
            set { hashString = value; RaisePropertyChanged("HashString"); }
        }

        #region Commands

        private RelayCommand commandGenerate;
        public RelayCommand CommandGenerate
        {
            get { return commandGenerate; }
            set { commandGenerate = value; RaisePropertyChanged("CommandGenerate"); }
        }

        private RelayCommand commandCopy;
        public RelayCommand CommandCopy
        {
            get { return commandCopy; }
            set { commandCopy = value; RaisePropertyChanged("CommandCopy"); }
        }

        #endregion

        #region Private Methods

        private void CommandCopyExecute()
        {
            Clipboard.SetData(DataFormats.Text, HashString);
        }
        
        private void CommandGenerateExecute()
        {
            this.HashString = Utils.GetPhysicalId();
        }

        #endregion
    }
}
